package club.banyuan.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
public class LoginController {
    @PostMapping("/login")
    public String login(String username, String password, Model model, RedirectAttributes redirectAttributes) {
        if (varify(username, password)) {
//            model.addAttribute("message","Login OK");
            redirectAttributes.addFlashAttribute("message","Login OK");
            return "redirect:/home_page";
        } else {
            redirectAttributes.addFlashAttribute("message","Login Error");
            return "redirect:/login";
        }
    }


    private boolean varify(String username, String password) {
        return "admin".equals(username) && "123456".equals(password);
    }
}
